package job2;

import java.util.Objects;

/*
(属性私有、空参有参构造、set、get方法、toString方法、equals方法、hashCode方法)，
包含三个属性：姓名(String name)、年龄(int age)、工资(double salary)
 */
public class Worker {
    private String name;
    private int age;
    private double salary;

//    无参构造
    public Worker() {
    }

//    有参构造
    public Worker(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

//    get set 方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

// toString
    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (null == o || getClass() != o.getClass()) return false;
        Worker w = (Worker) o;
        return age == w.age &&
                Double.compare(salary, w.salary) == 0 &&
                Objects.equals(name, w.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, salary);
    }

    public void work() {
        System.out.println(name + "正在工作");
    }
}
